import list_behavior from "../../../behavior/list_behavior";
import {simpleGet, simplePost} from "../../../utils/request";
import {showToast, showToastSuccess} from "../../../utils/tool";

const app = getApp()
const global = app.globalData

Page({
    behaviors:[list_behavior],
    data: {
        nav: {
            title:"领券中心"
        },
        options:{},
        imageUrl: global.imageUrl,
    },
    onLoad: function (options={}) {
        this.init(options)
    },
    init(options){
        this.setData({
            options,
            [`list.url`]: '/coupon/paginate',
            [`list.where`]:{}
        })
        this.setList(1)
    },
    // 领券
    getCoupon(e){
        const {list} = this.data
        const {index} = e.currentTarget.dataset
        const item = list.items[index]
        simplePost("/coupon/get", {id:item.id}).then(r => {
            this.setData({
                [`list.items[${index}].isGet`]:true,
            })
            showToastSuccess("领取成功")
        })
    },
});
